package com.yty.demo._6_collection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author: yangtaoyao
 * @time: 2020/1/13 12:13
 * @description: HashSet
 */
public class HashSetTest {
    public static void main(String[] args) {
        Set set=new HashSet();
        set.add(1);
        set.add("a");
        set.add(1);
        System.out.println(set);
        System.out.println(set.contains("a"));//是否包含
        set.clear();//清空
        set.add("a");
        set.add("B");
        set.add("c");
        System.out.println(set);
        System.out.println(set.size());//大小

        System.out.println(set.remove("A"));//false
        set.remove("a");
        System.out.println(set);

        //迭代器遍历
        Iterator it=set.iterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();

        //for each 遍历
        for (Object object:set) {
            System.out.print(object+" ");
        }
        System.out.println();

    }
}
